home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / mosmllib / test / word8vector.sml < prev   
Encoding:
Text File  |  1997-08-18  |  3.4 KB  |  104 lines  |  [TEXT/R*ch]

  1. (* test/vector.sml -- some test cases for Vector 
  2.    PS 1994-12-10, 1995-06-14 *)
  3.  
  4. use "auxil.sml";
  5.  
  6. local
  7.     open Word8Vector;
  8.     val i2w = Word8.fromInt;
  9.     infix 9 sub;
  10. in
  11.  
  12. val a = fromList (List.map i2w [0,1,2,3,4,5,6]);
  13. val b = fromList (List.map i2w [44,55,66]);
  14. val c = fromList (List.map i2w [0,1,2,3,4,5,6]);
  15.  
  16. val test1 = check'(fn _ => a<>b);
  17. val test2 = check'(fn _ => a=c);
  18.  
  19. val d = tabulate(100, fn i => i2w (i mod 7));
  20.  
  21. val test3 = check'(fn _ => d sub 27 = i2w 6);
  22.  
  23. val test4a = (tabulate(maxLen+1, i2w) seq "WRONG")
  24.              handle Size => "OK" | _ => "WRONG";
  25.  
  26. val test4b = (tabulate(~1, i2w)       seq "WRONG")
  27.              handle Size => "OK" | _ => "WRONG";
  28.  
  29. val test4c = check'(fn _ => length (tabulate(0, fn i => i2w (i div 0))) = 0);
  30.  
  31. val test5 = check'(fn _ => length (fromList []) = 0 andalso length a = 7);
  32.  
  33. val test6a = (c sub ~1 seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
  34. val test6b = (c sub 7  seq "WRONG") handle Subscript => "OK" | _ => "WRONG";
  35. val test6c = check'(fn _ => c sub 0 = i2w 0);
  36.  
  37. val e = concat [d, b, d];
  38.  
  39. val test7 = check'(fn _ => length e = 203);
  40.  
  41. val test8 = check'(fn _ => length (concat []) = 0);
  42.  
  43. val f = extract (e, 100, SOME 3);
  44.  
  45. val test9 = check'(fn _ => f = b);
  46.  
  47. val test9a = check'(fn _ => e = extract(e, 0, SOME (length e)) 
  48.             andalso e = extract(e, 0, NONE));
  49. val test9b = check'(fn _ => fromList [] = extract(e, 100, SOME 0));
  50. val test9c = (extract(e, ~1, SOME (length e))  seq "WRONG") 
  51.              handle Subscript => "OK" | _ => "WRONG"
  52. val test9d = (extract(e, length e + 1, SOME 0)  seq "WRONG") 
  53.              handle Subscript => "OK" | _ => "WRONG"
  54. val test9e = (extract(e, 0, SOME (length e+1)) seq "WRONG") 
  55.              handle Subscript => "OK" | _ => "WRONG"
  56. val test9f = (extract(e, 20, SOME ~1)        seq "WRONG") 
  57.              handle Subscript => "OK" | _ => "WRONG"
  58. val test9g = (extract(e, ~1, NONE)  seq "WRONG") 
  59.              handle Subscript => "OK" | _ => "WRONG"
  60. val test9h = (extract(e, length e + 1, NONE)  seq "WRONG") 
  61.              handle Subscript => "OK" | _ => "WRONG"
  62. val test9i = check'(fn _ => fromList [] = extract(e, length e, SOME 0)
  63.             andalso fromList [] = extract(e, length e, NONE));
  64.  
  65. fun chkiter iter f vec reslast =
  66.     check'(fn _ =>
  67.        let val last = ref 0w255
  68.            val res = iter (fn x => (last := x; f x)) vec
  69.        in (res, !last) = reslast end)
  70.  
  71. fun chkiteri iter f vec reslast =
  72.     check'(fn _ =>
  73.        let val last = ref ~1
  74.            val res = iter (fn (i, x) => (last := i; f x)) vec
  75.        in (res, !last) = reslast end)
  76.  
  77. val test10a = 
  78.     chkiter map (fn x => 0w2*x) b (fromList [0w88,0w110,0w132], 0w66)
  79.  
  80. val test11a = 
  81.     chkiteri mapi (fn x => 0w2*x) (b, 0, NONE) (fromList [0w88,0w110,0w132], 2)
  82. val test11b = 
  83.     chkiteri mapi (fn x => 0w2*x) (b, 1, NONE) (fromList [0w110,0w132], 2)
  84. val test11c = 
  85.     chkiteri mapi (fn x => 0w2*x) (b, 1, SOME 0) (fromList [], ~1)
  86. val test11d = 
  87.     chkiteri mapi (fn x => 0w2*x) (b, 1, SOME 1) (fromList [0w110], 1)
  88. val test11e = 
  89.     chkiteri mapi (fn x => 0w2*x) (b, 3, NONE) (fromList [], ~1)
  90.  
  91. val test11f =
  92.     (mapi #2 (b, 0, SOME 4) seq "WRONG") 
  93.     handle Subscript => "OK" | _ => "WRONG";
  94. val test11g =
  95.     (mapi #2 (b, 3, SOME 1) seq "WRONG") 
  96.     handle Subscript => "OK" | _ => "WRONG";
  97. val test11h =
  98.     (mapi #2 (b, 4, SOME 0) seq "WRONG") 
  99.     handle Subscript => "OK" | _ => "WRONG";
  100. val test11i =
  101.     (mapi #2 (b, 4, NONE) seq "WRONG") 
  102.     handle Subscript => "OK" | _ => "WRONG";
  103. end;
  104.